import pika

# 创建连接参数对象
credentials = pika.PlainCredentials('admin', 'admin')  # 使用你的用户名和密码
parameters = pika.ConnectionParameters(
    host='172.30.18.253',  # 服务器 IP 地址
    port=5672,              # AMQP 端口
    virtual_host='/',       # 虚拟主机
    credentials=credentials # 认证信息
)

# 建立连接
try:
    connection = pika.BlockingConnection(parameters)
    channel = connection.channel()
    print("连接成功！")
except Exception as e:
    print(f"连接失败: {e}")
    raise